<?php
/**
 * Created by a front-end programmer.
 * User: Xwen
 * Date: 2018/2/26
 * Time: 15:36
 * Mail:lauwencn@gmail.com
 */
class ArticleController extends CommonController{
    private $_model = NULL;
    public function __auto(){
        $this->_model = K('Article');
    }
    public function index(){
        $this->assign('data', $this->_model->get_all());
        $this->display();
    }
    public function add(){
        if(IS_POST){
            if(!$this->_model->add_data()){
                $this->error($this->_model->error);
            }
            $this->success('文章添加成功', __APP__."?c=Article&m=index");
        }
        $cateData = K('Category')->get_all();
        $this->assign('cateData', $cateData);
        $this->display();
    }
    public function del(){
        $this->_model->remove((int)$_GET['aid']);
        $this->success('删除成功！', __APP__."?c=Article&m=index");
    }
    public function edit(){
        if(IS_POST){
            if($this->_model->edit((int)$_GET['aid'])){
                $this->success('修改成功', __APP__."?c=Article&m=index");
            }
            $this->error($this->_model->error);
        }
        $oldData = $this->_model->get_one($_GET['aid']);
        $this->assign('oldData', $oldData);
        $cateData = K('Category')->get_all();
        $this->assign('cateData', $cateData);
        $this->display();
    }

}

?>